<?php
class Route_Content
{
    /**
     * Build friendly URL
     * @param array $linkArr 0 => <module>, 1 => controller, 2 => action, 3...n param/value
     * @param array $params param => value
     * 
     * @return string friendly URL
     */
    public function build($linkArr, $params = array()) 
    {
    	
    	$result = implode('/', $linkArr);
    	
    	/**
    	 * Link is detail
    	 */
    	if ('gioithieu' == @$linkArr[2]) {
    		/**
	    	 * Structure: pages/<id>/<alias>.html
	    	 */
    		$result = "pages/{$linkArr[4]}/";
	    	if (null != $params['alias']) {
	    		$result .= urlencode($params['alias']);
	    	}
    		 
    	}
    if ('line' == @$linkArr[2]) {
    		/**
	    	 * Structure: pages/<id>/<alias>.html
	    	 */
    		$result = "line/{$linkArr[4]}/";
	    	if (null != $params['alias']) {
	    		$result .= urlencode($params['alias']);
	    	}
    		 
    	}
    	if ('index' == @$linkArr[2]) {
    		/**
	    	 * Structure: pages/<id>/<alias>.html
	    	 */
    		$result = "catagories/{$linkArr[4]}/";
	    	if (null != $params['alias']) {
	    		$result .= urlencode($params['alias']);
	    	}
    		 
    	}
    	if ('hopdong' == @$linkArr[2]) {
    		/**
	    	 * Structure: pages/<id>/<alias>.html
	    	 */
    		$result = "hopdong/{$linkArr[4]}/";
	    	if (null != $params['alias']) {
	    		$result .= urlencode($params['alias']);
	    	}
    		 
    	}
    	
    	if ('intro' == @$linkArr[2]) {
    		/**
	    	 * Structure: pages/<id>/<alias>.html
	    	 */
    		$result = "page/{$linkArr[4]}/";
	    	if (null != $params['alias']) {
	    		$result .= urlencode($params['alias']);
	    	}
    	}
    	if ('detail' == @$linkArr[2]) {
    		/**
	    	 * Structure: pages/<id>/<alias>.html
	    	 */
    		$result = "view/{$linkArr[4]}/";
	    	if (null != $params['alias']) {
	    		$result .= urlencode($params['alias']);
	    	}
    	}
    	return $result;
    	
    }
    /**
     * Parse friendly URL
     */
    public function parse()
    {
         $router = Nine_Controller_Front::getInstance()->getRouter();
         $route  = new Zend_Controller_Router_Route_Regex(
                                                 'pages/([0-9]+)/(.*).html',
                                                 array(
                                                    'module'     => 'content',
                                                    'controller' => 'index',
                                                    'action'     => 'gioithieu'
                                                 ),
                                                 array(1 =>'id')
                                            );
         $router->addRoute('content', $route); 

         $route1  = new Zend_Controller_Router_Route_Regex(
                                                 'catagories/([0-9]+)/(.*).html',
                                                 array(
                                                    'module'     => 'content',
                                                    'controller' => 'index',
                                                    'action'     => 'index'
                                                 ),
                                                 array(1 =>'cid')
                                            );
         $router->addRoute('content1', $route1); 
         $route2  = new Zend_Controller_Router_Route_Regex(
                                                 'page/([0-9]+)/(.*).html',
                                                 array(
                                                    'module'     => 'content',
                                                    'controller' => 'index',
                                                    'action'     => 'intro'
                                                 ),
                                                 array(1 =>'cid')
                                            );
         $router->addRoute('content2', $route2); 
         $route3  = new Zend_Controller_Router_Route_Regex(
                                                 'hopdong/([0-9]+)/(.*).html',
                                                 array(
                                                    'module'     => 'content',
                                                    'controller' => 'index',
                                                    'action'     => 'hopdong'
                                                 ),
                                                 array(1 =>'id')
                                            );
         $router->addRoute('content33', $route3); 
         $route4  = new Zend_Controller_Router_Route_Regex(
                                                 'view/([0-9]+)/(.*).html',
                                                 array(
                                                    'module'     => 'content',
                                                    'controller' => 'index',
                                                    'action'     => 'detail'
                                                 ),
                                                 array(1 =>'id')
                                            );
         $router->addRoute('content4', $route4); 
         $route5  = new Zend_Controller_Router_Route_Regex(
                                                 'line/([0-9]+)/(.*).html',
                                                 array(
                                                    'module'     => 'content',
                                                    'controller' => 'index',
                                                    'action'     => 'line'
                                                 ),
                                                 array(1 =>'id')
                                            );
         $router->addRoute('content5', $route5);
    }
}